package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.LmTicketCatalogBig;
import cn.wolfcode.trip.base.domain.LmTicketCatalogBig;
import cn.wolfcode.trip.base.domain.LtCatalogDetail;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.mapper.LmTicketCatalogBigMapper;
import cn.wolfcode.trip.base.mapper.LtCatalogDetailMapper;
import cn.wolfcode.trip.base.query.LtCatalogDetailQueryObject;
import cn.wolfcode.trip.base.service.ILmTicketCatalogBigService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LmTicketCatalogBigServiceImpl implements ILmTicketCatalogBigService {
    @Autowired
    private LmTicketCatalogBigMapper lmTicketCatalogBigMapper;
    @Autowired
    private LtCatalogDetailMapper ltCatalogDetailMapper;


    @Override
    public void save(LmTicketCatalogBig lmTicketCatalogBig) {
        lmTicketCatalogBigMapper.insert(lmTicketCatalogBig);
    }

    @Override
    public void delete(Long id) {
        lmTicketCatalogBigMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<LmTicketCatalogBig> selectAll() {
        return lmTicketCatalogBigMapper.selectAll();
    }

    @Override
    public void update(LmTicketCatalogBig lmTicketCatalogBig) {
        lmTicketCatalogBigMapper.updateByPrimaryKey(lmTicketCatalogBig);
    }

    @Override
    public LmTicketCatalogBig get(Long id) {
        return lmTicketCatalogBigMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<LmTicketCatalogBig> getLmTicketCatalogBigByState(int state) {
        return lmTicketCatalogBigMapper.selectLmTicketCatalogBigByState(state);
    }

    @Override
    public PageInfo getSpecialCommendByState(LtCatalogDetailQueryObject qo) {
        //当前页,和页面显示条数
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        //准备基本sql
        List<LmTicketCatalogBig> list = lmTicketCatalogBigMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo query(LtCatalogDetailQueryObject qo2) {
        //当前页,和页面显示条数
        PageHelper.startPage(qo2.getCurrentPage(),qo2.getPageSize());
        //准备基本sql
        List<LmTicketCatalogBig> list = lmTicketCatalogBigMapper.selectForCatalog(qo2);
        return new PageInfo(list);
    }

    @Override
    public List<LmTicketCatalogBig> selectCatalogByParentId(Long parentId) {
        return lmTicketCatalogBigMapper.selectCatalogByParentId(parentId);
    }
    @Override
    public void saveOrUpdate(LmTicketCatalogBig lmTicketCatalogBig,String imgUrl) {
        if(lmTicketCatalogBig.getId()!=null){
            //图片表的cbId和图片
            Long id = lmTicketCatalogBig.getId();
            //原本图片对象
            LtCatalogDetail detail = ltCatalogDetailMapper.getIdByCatalogBigId(id);
            detail.setCoverUrl(imgUrl);
            ltCatalogDetailMapper.updateByPrimaryKey(detail);
            lmTicketCatalogBigMapper.updateByPrimaryKey(lmTicketCatalogBig);
        }else{
            lmTicketCatalogBigMapper.insert(lmTicketCatalogBig);

            LtCatalogDetail ltCatalogDetail=new LtCatalogDetail();
            ltCatalogDetail.setCoverUrl(imgUrl);
            ltCatalogDetailMapper.insert(ltCatalogDetail);
            ltCatalogDetailMapper.updateCbId(lmTicketCatalogBig.getId(),ltCatalogDetail.getId());
        }
    }

    @Override
    public List<LmTicketCatalogBig> getCatalogBigBypId(Long specialSubCommendId) {
        return lmTicketCatalogBigMapper.getCatalogBigBypId(specialSubCommendId);
    }

    @Override
    public List<LmTicketCatalogBig> getLmTicketCatalogBigByStateTwo(int state) {
        int stateTwo=0;
        return lmTicketCatalogBigMapper.getLmTicketCatalogBigByStateTwo(state,stateTwo);
    }
}
